#添加任务页面类

from time import sleep
from selenium import webdriver
from selenium.webdriver.common.by import By

#数据
driver = webdriver.Chrome()
driver.maximize_window()
driver.get('http://192.168.1.83/crm')
username = 'zhangsan'   #用户名
password = '123456'      #密码
subiect = '红红火火恍恍惚惚暴龙战士'  #添加任务中的主题内容

#元素定位器
username_locator = (By.NAME,'name')      #登录账号
password_locator = (By.NAME, 'password')  #登录密码
btn_locator = (By.NAME,'submit')        #点击登录按钮
task_locator = (By.LINK_TEXT, '任务')  # 任务模块
newtask_locator = (By.LINK_TEXT, '新建任务')  # 新建任务
subiect_locator = (By.ID,'subject')    #添加任务中的主题
principal_locator = (By.ID,'owner_name') #添加任务中负责人
entirebtn_locator = (By.XPATH,'//*[@id="ta1"]/span[1]/input') #选择添加任务中第一位admin负责人
okbtn_locator = (By.XPATH,'/html/body/div[7]/div[3]/div/button[1]') #选择添加任务中选择负责人ok按钮
correlation_locator = (By.ID,'about_roles_name')   #选择任务相关人
correlation_principal_locator = (By.XPATH,'//*[@id="ta1"]/input')  #选择添加任务相关人全部负责人
correlation_okbtn_locator = (By.XPATH,'/html/body/div[8]/div[3]/div/button[1]')   #任务相关人点击ok保存
save_locator = (By.XPATH,'/html/body/div[5]/div[2]/div/form/table/tfoot/tr/td[2]/input[1]')  #   添加任务中的保存按钮


# 操作方法
# 输入用户名
username_element = driver.find_element(*username_locator).send_keys(username)

 # 输入用户名
password_element = driver.find_element(*password_locator).send_keys(password)
sleep(2)

 # 点击登录
btn_element = driver.find_element(*btn_locator).click()
sleep(2)

#点击任务
task_element = driver.find_element(*task_locator).click()

#点击新建任务
newtask_element = driver.find_element(*newtask_locator).click()
sleep(2)

#点击主题并添加内容
subiect_element = driver.find_element(*subiect_locator).send_keys(subiect)

#点击负责人，选择，保存
principal_element = driver.find_element(*principal_locator).click()
sleep(2)
entirebtn_element = driver.find_element(*entirebtn_locator).click()  #选择全部负责人
sleep(2)
okbtn_element = driver.find_element(*okbtn_locator).click() #选择负责人后点击保存
sleep(2)

#点击相关人，选择全部负责人，保存
correlation_element = driver.find_element(*correlation_locator).click()
sleep(2)
correlation_principal_element = driver.find_element(*correlation_principal_locator).click()
sleep(2)
correlation_okbtn_element = driver.find_element(*correlation_okbtn_locator).click()
sleep(5)
#点击保存按钮
save_element = driver.find_element(*save_locator).click()

sleep(5)
driver.quit()






